package com.lj.ljminsu.userClient.controller;

import com.lj.ljminsu.bean.JsonResultVo;
import com.lj.ljminsu.bean.TjUser;
import com.lj.ljminsu.bean.UserThreadLocal;
import com.lj.ljminsu.userClient.bean.OrderBean;
import com.lj.ljminsu.userClient.service.IOrderListService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("order")
public class OrderListController {

    @Resource
    private IOrderListService iOrderListService;

    @CrossOrigin
    @RequestMapping("list")
    public List<OrderBean> toOrderList() {
        System.out.println("进来了1");
        TjUser tjUser = UserThreadLocal.get();
        String userPhone = tjUser.getUserPhone();
        List<OrderBean> orderBeans = iOrderListService.selectOrderListByUserPhone(userPhone);

        return orderBeans;
    }

    @RequestMapping("deleteOrder")
    public JsonResultVo deleteOrderList(String orderId) {
        int orderNum = Integer.parseInt(orderId);
        JsonResultVo jsonResultVo = new JsonResultVo();
        System.out.println("进来了2");
        iOrderListService.deleteOrderByOrderId(orderNum);
        jsonResultVo.setCode(0);
        jsonResultVo.setMsg("订单删除成功");
        return jsonResultVo;
    }
}
